package com.interview.strategy;

import com.interview.domain.OrderItem;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
public class DiscountPricingStrategy extends PricingStrategy {
    private double discountRate;
    public DiscountPricingStrategy(double discountRate) {
        this.discountRate = discountRate;
    }

    @Override
    public OrderItem calculateCost(BigDecimal price, BigDecimal quantity,String title) {
        BigDecimal total = quantity.multiply(price)
                .multiply(new BigDecimal(String.valueOf(discountRate)))
                .setScale(2,RoundingMode.UP);
        OrderItem orderItem = new OrderItem();
        orderItem.setTitle(title);
        orderItem.setPrice(price.doubleValue());
        orderItem.setTotal(total);
        orderItem.setQuantity(quantity.doubleValue());
        orderItem.setDiscount(discountRate);
        return orderItem;
    }
}
